using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NServiceBus.ObjectBuilder.MugenInjection;
using NUnit.Framework;
using IContainer = NServiceBus.ObjectBuilder.Common.IContainer;

namespace ObjectBuilder.Tests
{
    public class BuilderFixture
    {
        protected virtual Action<IContainer> InitializeBuilder()
        {
            //no-op
            return (c) => { };
        }

        private IList<IContainer> objectBuilders;

        protected void ForAllBuilders(Action<IContainer> assertion, params Type[] containersToIgnore)
        {
            foreach (var builder in objectBuilders.Where(b => !containersToIgnore.Contains(b.GetType())))
            {
                assertion(builder);
            }
        }

        [SetUp]
        public void SetUp()
        {
            objectBuilders = new List<IContainer>
                {
                    //add all supported builders here
                    new MugenInjectionObjectBuilder()
                };

            var inilialize = InitializeBuilder();

            foreach (var builder in objectBuilders)
            {
                try
                {
                    inilialize(builder);
                }
                catch (NotSupportedException)
                {
                    // this is expected for SpringBuilder and Unity when running Configure<T>(Func<T>)                    
                }
            }
        }
    }
}